﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.ViewModel.Month
{
    public class CompanyMonthSort
    {
        /// <summary>
        /// 左侧菜单显示信息
        /// </summary>
        public LeftMenuInfos LeftMenuInfos { get; set; }

        public string DateQuery { get; set; }

        public Benefit.Models.Sys.Company Company { get; set; }

        public string QueryYear { get; set; }

        public string QueryMonth { get; set; }

        public string Pdate { get; set; }

        public List<Benefit.Models.Month.GroupMonthSum> GroupMonthSum { get; set; }

        public List<Benefit.Models.Month.BrokerageMonthTradeInfo> BrokerageMonthTradeInfo { get; set; }

        #region 定义一些使用到的接口
        private Interface.Sys.ICompany ICompany = null;
        private Interface.Sys.ITradeHistory ITradeHistory = null;
        private Interface.Month.IGroupMonthSum IGroupMonthSum = null;
        private Interface.Month.IBrokerageMonthTradeInfo IBrokerageMonthTradeInfo = null;
        #endregion



        public CompanyMonthSort(int queryDate, DB.DBManager db)
        {
            InitInterface(db);
            this.DateQuery = queryDate.ToString();
            this.Company = ICompany.GetCompany();

            this.QueryYear = queryDate.ToString().Substring(0, 4);
            this.QueryMonth = queryDate.ToString().Substring(4, 2);

            this.GroupMonthSum = IGroupMonthSum.GetGroupMonthSum(Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear)).OrderByDescending(a => a.Profit).ToList();

            this.BrokerageMonthTradeInfo = IBrokerageMonthTradeInfo.GetBrokerageMonthTradeInfo(Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));

            DisposeInterface();
        }



        private void InitInterface(DB.DBManager db)
        {
            #region 初始化接口
            ICompany = new Service.Sys.ServiceCompany(db);
            ITradeHistory = new Service.Sys.ServiceTradeHistory(db);
            IGroupMonthSum = new Service.Month.ServiceGroupMonthSum(db);
            IBrokerageMonthTradeInfo = new Service.Month.ServiceBrokerageMonthTradeInfo(db);
            #endregion
        }
        /// <summary>
        /// 释放接口
        /// </summary>
        private void DisposeInterface()
        {
            #region 释放接口
            ICompany = null;
            ITradeHistory = null;
            IGroupMonthSum = null;
            IBrokerageMonthTradeInfo = null;
            #endregion
        }
    }
}
